/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;

import static java.util.Collections.unmodifiableList;
import static java.util.stream.Collectors.toList;

/**
 *
 * @author 专辑
 */
public final class Album implements Performance {

    private String name;
    private List<Track> tracks;
    private List<Artist> musicians;


    public Album(String name, List<Track> tracks, List<Artist> musicians) {
        Objects.requireNonNull(name);
        Objects.requireNonNull(tracks);
        Objects.requireNonNull(musicians);

        this.name = name;
        this.tracks = new ArrayList<>(tracks);
        this.musicians = new ArrayList<>(musicians);
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the tracks
     */
    public Stream<Track> getTracks() {
        return tracks.stream();
    }

    /**
     * Used in imperative code examples that need to iterate over a list
     */
    public List<Track> getTrackList() {
        return unmodifiableList(tracks);
    }

    /**
     * @return the musicians
     */
    public Stream<Artist> getMusicians() {
        return musicians.stream();
    }

    /**
     * Used in imperative code examples that need to iterate over a list
     */
    public List<Artist> getMusicianList() {
        return unmodifiableList(musicians);
    }

    public Artist getMainMusician() {
        return musicians.get(0);
    }

    public Album copy() {
        List<Track> tracks = getTracks().map(Track::copy).collect(toList());
        List<Artist> musicians = getMusicians().map(Artist::copy).collect(toList());
        return new Album(name, tracks, musicians);
    }

    public static List<Album> initAlbum(){
        List<Track> tracks =  new ArrayList<>();
        tracks.add(new Track("我的地盘",5));
        tracks.add(new Track("七里香",4));
        tracks.add(new Track("借口",3));
        tracks.add(new Track("外婆",2));
        tracks.add(new Track("将军",5));
        tracks.add(new Track("搁浅",3));
        tracks.add(new Track("乱舞春秋",4));
        List<Artist> musicians = new ArrayList<>();
        musicians.add(new Artist("周杰伦","台湾"));
        musicians.add(new Artist("方文山","台湾"));
        musicians.add(new Artist("钟兴民","北京"));
        Album album1 = new Album("七里香",tracks,musicians);

        List<Track> tracks1 =  new ArrayList<>();
        tracks1.add(new Track("月亮之上",5));
        tracks1.add(new Track("荷塘月色",4));
        tracks1.add(new Track("传奇",3));
        List<Artist> musicians1 = new ArrayList<>();
        List<Artist> artists = Arrays.asList(new Artist("玲花", "东北"),
                new Artist("曾毅", "内蒙古"));
        musicians1.add(new Artist("凤凰传奇",artists,"东北"));

        Album album2 = new Album("月亮之上",tracks1,musicians1);
        return Arrays.asList(album1,album2);
    }

}